<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
  <th:block th:include="include :: header('分配方案选择产品')" />
</head>

<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12">
      <form id="select-micro-form">
        <input type="hidden" id="planId" name="planId" th:value="${planId}">
      </form>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var datas = [[${@dict.getType('micro_unit_type')}]];
  var mpdatas = [[${@dict.getType('micro_pharm_type')}]];
  var prefix = ctx + "sewage/sewagePlan";

  $(function() {
    var options = {
      url: prefix + "/unMicroList",
      queryParams: queryParams,
      modalName: "菌剂",
      showSearch: false,
      showRefresh: false,
      showToggle: false,
      showColumns: false,
      clickToSelect: true,
      rememberSelected: true,
      columns: [{
        field: 'state',
        checkbox: true
      },
        {
          field: 'microbialId',
          title: '菌剂ID',
          visible: false,
        },
        {
          field: 'microbialType',
          title: '菌剂类型',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(mpdatas, value);
          }
        },
        {
          field: 'microbialName',
          title: '菌剂名称',
        },
        {
          field: 'microbialLogoUrl',
          title: '产品图片',
          formatter: function(value, row, index) {
            return $.table.imageView(value, '/abvfile/micro');
          }
        },
        {
          field: 'microbialSpec',
          title: '产品规格',
        },
        {
          field: 'microbialUnit',
          title: '产品单位',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(datas, value);
          }
        },
        {
          field: 'microbialPrice',
          title: '菌剂价格(元)'
        }]
    };
    $.table.init(options);
  });

  function queryParams(params) {
    var search = $.table.queryParams(params);
    search.planId = $("#planId").val();
    return search;
  }

  function submitHandler() {
    var rows = $.table.selectFirstColumns();
    if (rows.length == 0) {
      $.modal.alertWarning("请至少选择一条记录");
      return;
    }
    var data = { "planId": $("#planId").val(), "microbialIds": rows.join() };
    $.operate.save(prefix + "/microSelectAll", data);
  }
</script>
</body>
</html>